$(function() {
	/*===图片懒加载===*/
	start();
	$(window).on('scroll', function() {
		start();
	});
	/*===图片轮播===*/
	var indexBanner = new Swiper('.indexBanner .swiper-container', {
		pagination: '.indexBanner .swiper-pagination',
		paginationClickable: '.indexBanner .swiper-pagination',
		autoplay: 4000,
		autoplayDisableOnInteraction: false,
		effect: 'effect'
	});
	/*===购票订单===*/
	if ($(".order").length > 0) {
		var date = new Date();
		var date30 = new Date();
		date30 = DateAdd("m ",1, date30);
		var year = date.getFullYear();
		var year30 = date30.getFullYear();
		var month = date.getMonth() + 1;
		var month30 = date30.getMonth() + 1;
		var day = date.getDate(); 
		var day30 = date30.getDate(); 
		var week = date.getDay();
		var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
		$("#today").text(year + '-' + month + '-' + day + ' ' + weeks[week]);
		$("#dateSelect").val(year + '-' + month + '-' + day );
		$("#dateSelect").attr({
			"data-year": year,
			"data-month": month,
			"data-day": day
		})
		new Mdate("dateSelect", {
			acceptId: "dateSelect",
			beginYear: year,
			beginMonth: month,
			beginDay: day,
			endYear: year30,
			endMonth: month30,
			endDay: day30
		});
		$("#payBtn").click(function(){
			var name = $("#name").val();
			var mobile = $("#mobile").val();
			var date = $("#dateSelect").val();
			if(!name){
				layer.msg("购票人不能为空!");
				return false;
			}
			if(!mobile){
				layer.msg("手机号不能为空!");
				return false;
			}
			var reg = /(1[3-9]\d{9}$)/;
			if(!reg.test(mobile)) {
				layer.msg("手机号格式不正确!");
				return false;
			}
			//调起支付
			
		})
	};
	/*===预订表单===*/
	if ($(".yudingForm").length > 0) {
		var date1 = new Date();
		var date30 = new Date();
		date1 = DateAdd("d ",1, date1);
		date30 = DateAdd("m ",1, date30);
		var year1 = date1.getFullYear();
		var year30 = date30.getFullYear();
		var month1 = date1.getMonth() + 1;
		var month30 = date30.getMonth() + 1;
		var day1 = date1.getDate(); 
		var day30 = date30.getDate(); 
		$("#dateSelect").val(year1 + '-' + month1 + '-' + day1 );
		$("#dateSelect").attr({
			"data-year": year1,
			"data-month": month1,
			"data-day": day1
		})
		new Mdate("dateSelect", {
			acceptId: "dateSelect",
			beginYear: year1,
			beginMonth: month1,
			beginDay: day1,
			endYear: year30,
			endMonth: month30,
			endDay: day30
		});
		new Rolldate({
			el: '#timeSelect',
			format: 'hh:mm',
			lang: { title: '&nbsp;'}
		});
		$("#yudingBtn").click(function(){
			var date = $("#dateSelect").val();
			var time = $("#timeSelect").val();
			var mobile = $("#mobile").val();
			var content = $("#content").val();
			if(!time){
				layer.msg("时间不能为空!");
				return false;
			}
			if(!mobile){
				layer.msg("手机号不能为空!");
				return false;
			}
			var reg = /(1[3-9]\d{9}$)/;
			if(!reg.test(mobile)) {
				layer.msg("手机号格式不正确!");
				return false;
			}
			if(!content){
				layer.msg("预订内容不能为空!");
				return false;
			}
			window.location.href="yudingOrder.html";
		})
	};
	/*===预订订单===*/
	if ($(".yudingOrder").length > 0) {
		var date = new Date();
		var year = date.getFullYear();
		var month = date.getMonth() + 1;
		var day = date.getDate(); 
		var week = date.getDay();
		var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
		$("#today").text(year + '-' + month + '-' + day + ' ' + weeks[week]);
		
		$("#payBtn").click(function(){
			var name = $("#name").val();
			var mobile = $("#mobile").val();
			if(!name){
				layer.msg("预订人不能为空!");
				return false;
			}
			if(!mobile){
				layer.msg("手机号不能为空!");
				return false;
			}
			var reg = /(1[3-9]\d{9}$)/;
			if(!reg.test(mobile)) {
				layer.msg("手机号格式不正确!");
				return false;
			}
			//调起支付
			
		})
	}
	/*===预订订单===*/
	$("#tcClose").click(function(){
		$(".adsTc").stop().fadeOut();
	});
	/*===个人资料===*/
	$("#noticeBtn").click(function(){
		$(".notice").stop().fadeIn();
	});
	$(".infoClose").click(function(){
		$(".notice").stop().fadeOut();
	});
	/*===加入会员===*/
	if ($(".join").length > 0) {
		var date = new Date();
		var year = date.getFullYear();
		new Rolldate({
			el: '#dateSelect',
			format: 'YYYY-MM-DD',
			beginYear: 1900,
			endYear: year,
			lang: { title: '&nbsp;'}
		});
		$("#joinBtn").click(function(){
			var name = $("#name").val();
			var date = $("#dateSelect").val();			
			var mobile = $("#mobile").val();
			var idCard = $("#idCard").val();
			if(!name){
				layer.msg("姓名不能为空!");
				return false;
			}
			if(!date){
				layer.msg("生日不能为空!");
				return false;
			}
			if(!mobile){
				layer.msg("手机号不能为空!");
				return false;
			}
			var reg = /(1[3-9]\d{9}$)/;
			if(!reg.test(mobile)) {
				layer.msg("手机号格式不正确!");
				return false;
			}
			if(!idCard){
				layer.msg("身份证号码不能为空!");
				return false;
			}
			var reg2 = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
			if(!reg2.test(idCard)) {
				layer.msg("身份证号错误!");
				return false;
			}
		})
	}
	/*===退票===*/
	$("#tuipiao").click(function(){
		$(".tuipiaoTc").stop().fadeIn();
	});
	$("#tpClose").click(function(){
		$(".tuipiaoTc").stop().fadeOut();
	});
	
});
/*===图片懒加载===*/
function start() {
	$('img').not('[data-isLoaded]').each(function() {
		var $node = $(this)
		if (isShow($node)) {
			loadImg($node)
		}
	})
}

function isShow($node) {
	return $node.offset().top <= $(window).height() + $(window).scrollTop();
}

function loadImg($img) {
	$img.attr('src', $img.attr('data-src'));
	$img.attr('data-isLoaded', 1);
}
/*===tab切换===*/
function tabChange(tab, con, ac) {
	$(tab).click(function() {
		var i = $(this).index();
		$(this).addClass(ac).siblings().removeClass(ac);
		$(con).eq(i).addClass(ac).siblings().removeClass(ac);
	});
}
/*===发送验证码倒计时===*/
function settime(obj, time) {
	var countdown = time;
	if (countdown == 0) {
		obj.removeClass('disabled');
		obj.text("获取验证码");
		countdown = 60;
		return;
	} else {
		obj.addClass('disabled');
		obj.text("重新发送(" + countdown + ")");
		countdown--;
	}
	setTimeout(function() {
		settime(obj, countdown)
	}, 1000)
}
/*===倒计时跳转===*/
function jump(count, dom, url) {
	window.setTimeout(function() {
		count--;
		if (count > 0) {
			dom.html(count + 's');
			jump(count, dom, url);
		} else {
			location.href = url;
		}
	}, 1000);
}
/*===日期增加===*/
function DateAdd(interval, number, date) {
    switch (interval) {
    case "y ": {
        date.setFullYear(date.getFullYear() + number);
        return date;
        break;
    }
    case "q ": {
        date.setMonth(date.getMonth() + number * 3);
        return date;
        break;
    }
    case "m ": {
        date.setMonth(date.getMonth() + number);
        return date;
        break;
    }
    case "w ": {
        date.setDate(date.getDate() + number * 7);
        return date;
        break;
    }
    case "d ": {
        date.setDate(date.getDate() + number);
        return date;
        break;
    }
    case "h ": {
        date.setHours(date.getHours() + number);
        return date;
        break;
    }
    case "m ": {
        date.setMinutes(date.getMinutes() + number);
        return date;
        break;
    }
    case "s ": {
        date.setSeconds(date.getSeconds() + number);
        return date;
        break;
    }
    default: {
        date.setDate(d.getDate() + number);
        return date;
        break;
    }
    }
}